const mongoose = require('mongoose')
const {
	DBHOST,
	DBPORT,
	DBNAME
} = require('./config/dbInfo')
mongoose.connect(`mongodb://${DBHOST}:${DBPORT}/${DBNAME}`)
module.exports = function (success, error) {
	if (typeof error !== 'function') {
		error = () => {
			console.log('连接失败~~~')
		}
	}
	mongoose.connection.once('open', () => {
		success()
	})
	mongoose.connection.on('error', () => {
		error()
	})
	mongoose.connection.on('close', () => {
		console.log('连接断开')
	})
}